
/**
 * 查找数组中是否有两个值的和为target
 * @param {*} nums 
 * @param {*} target 
 * 返回下标
 */
function twoSums(nums, target) {
  let map = new Map();
  for(let i = 0; i < nums.length; i++) {
    const complete = target - nums[i];
    if (map.has(complete)) {
        return [map.get(complete), i];
    }
    map.set(nums[i], i);
  }
}

//[3,2,4] target = 6
function twoSums2(nums, target) {
    for(let i = 0; i < nums.length; i++) {
        const completeIndex = nums.indexOf(target - nums[i]);
        if (completeIndex != -1 && completeIndex !== i) {
            return [i, completeIndex];
        }
    }
}
console.log(twoSums2([3,2,4], 6));
